<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/3 0003
 * Time: 下午 2:50
 */
namespace app\admin\controller;

use think\Controller;
use app\admin\model\AdminUser;

class Admin extends Controller{
    public function add(){
        if(request()->isPost()){
            $data = input('post.');
            $validate = validate('AdminUser');
            if(!$validate->check($data)){
                $this->error($validate->getError());
            }
            $data['salt'] = getSalt();
            $data['password'] = md5($data['password'].$data['salt']);
            $data['status'] = 1;
            $model = new AdminUser();
            try{
                $id = $model->add($data);
            }catch (\Exception $e){
                echo $e->getMessage();
            }
            if($id){
                $this->success('id='.$id.'的用户新增成功');
            }else{
                $this->error('error');
            }

        }else{
            return $this->fetch();
        }

    }
}